################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Analysis ESS
#Figure B 8
#
#Verena Fetscher
#July 2022
####################

####################
# Load data
####################
source("dataframes.R")


##########################
#Benefit concentration indicators versus alternative measures: Benefit concentration and fiscal redistribution (benefits) by Mahler and Jesuit (2006)
##########################

cor.test(data_sub$red_transfers,data_sub$benefitsAvgYear, method=c("pearson"))

##########################
# Produces Figure B.8: Benefit concentration and fiscal redistribution achieved via transfers.
##########################


data_sub%>%
  group_by(country)%>%
  summarize(benefits=mean(benefitsAvg),
            red_transfers=mean(red_transfers,na.rm=T))%>%
  ggplot(aes(x=benefits, y=red_transfers)) + 
  geom_point() + 
  #ggtitle("Benefit concentration and fiscal redistribution (via transfers)") + 
  geom_smooth(method=lm, se=T) + 
  scale_x_continuous(name = "Benefit concentration", limits = c(0, 1)) + 
  scale_y_continuous(name = "Fiscal redistribution (via transfers)") + 
  theme_bw()


##########################
#Save figure
##########################

ggsave(file="figure_b8.pdf", height = 5.83, width = 8.27, units = "in")

